/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: jse2204 - StringBuilderDemo
 * <p>Powered by webrx On 2022-09-14 09:48:07
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        //m1();
        StringBuilder sbu = new StringBuilder();
        sbu.append("hello");
        sbu.append(18);
        sbu.insert(1, "Welcome - ");
        //sbu.append("Welcome - ");
        //sbu.append("Welcome - ",0,"Welcome - ".length());
        System.out.println(sbu);

        System.out.println(sbu.toString().concat("java"));
        sbu.delete(0, 5);
        System.out.println(sbu);
        //错误的
        //String s = sbu;

        //String 转换为  StringBuilder
        String s1 = "hello";
        StringBuilder ss1 = new StringBuilder(s1);
        System.out.println(s1);
        System.out.println(ss1);
        System.out.println(ss1.toString());
        System.out.println(ss1.reverse().append("java.18").toString().toUpperCase());

        //StringBuilder 转换为  String
        String s2 = ss1.toString();
        System.out.println(s2);
    }


    public static void m1() {
        StringBuilder su1 = new StringBuilder();
        StringBuilder su2 = new StringBuilder(6);
        StringBuilder su3 = new StringBuilder("hello");
        System.out.println(su1);
        System.out.println(su1.length());
        System.out.println(su2);
        System.out.println(su2.length());
        System.out.println(su3);
        System.out.println(su3.length());

        StringBuffer suf1 = new StringBuffer();
        StringBuffer suf2 = new StringBuffer(6);
        StringBuffer suf3 = new StringBuffer("hello");
        System.out.println(suf1);
        System.out.println(suf1.length());
        System.out.println(suf2);
        System.out.println(suf2.length());
        System.out.println(suf3);
        System.out.println(suf3.length());
    }
}
